package edu.guet.server.utils;

import lombok.Data;

/**@description 数据反馈基类*/
@Data
public class ResultAPI<T> {
    private int status;  //响应状态
    private String msg; //相应消息
    private T data;  //响应结果
    private String code;//响应代码

    public ResultAPI(){}
    public ResultAPI(T data, String msg, int status) {
        this.data = data;
        this.msg = msg;
        this.status = status;
    }


    /** 成功 **/
    public static ResultAPI success() {
        return success(null);
    }
    /** 成功 **/
    public static ResultAPI success(Object data) {
        ResultAPI result = new ResultAPI();
        result.setCode(ExceptionEnum.SUCCESS.getResultCode());
        result.setMsg(ExceptionEnum.SUCCESS.getResultMsg());
        result.setData(data);
        result.setStatus(1);
        return result;
    }

    public static ResultAPI success(Object data, String message) {
        ResultAPI result = new ResultAPI();
        result.setCode(ExceptionEnum.SUCCESS.getResultCode());
        result.setMsg(message);
        result.setData(data);
        result.setStatus(1);
        return result;
    }

    /** 失败 **/
    public static ResultAPI error(BaseInfoInterface errorInfo) {
        ResultAPI result = new ResultAPI();
        result.setCode(errorInfo.getResultCode());
        result.setMsg(errorInfo.getResultMsg());
        result.setData(null);
        result.setStatus(0);
        return result;
    }
    /** 失败 **/
    public static ResultAPI error(String code, String message) {
        ResultAPI result = new ResultAPI();
        result.setCode(code);
        result.setMsg(message);
        result.setData(null);
        result.setStatus(0);
        return result;
    }
    /** 失败 **/
    public static ResultAPI error(String message) {
        ResultAPI result = new ResultAPI();
        result.setStatus(0);
        result.setMsg(message);
        result.setData(null);
        return result;
    }

}
